package com.shd.edanpei.base.data;


import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.shd.edanpei.base.MyApplication;

public final class Preference {

    //意见反馈
    public static final String OPINION = "opinion";

    private static final SharedPreferences PREFERENCES =
            PreferenceManager.getDefaultSharedPreferences(MyApplication.getApplication());
    private static final String APP_PREFERENCES_KEY = "profile";

    private static SharedPreferences getAppPreference() {
        return PREFERENCES;
    }

    public static void setProfile(String val) {
        getAppPreference()
                .edit()
                .putString(APP_PREFERENCES_KEY, val)
                .apply();
    }

    public static String getProfile() {
        return getAppPreference().getString(APP_PREFERENCES_KEY, null);
    }


    public static void removeProfile() {
        getAppPreference()
                .edit()
                .remove(APP_PREFERENCES_KEY)
                .apply();
    }

    public static void clear() {
        getAppPreference()
                .edit()
                .clear()
                .apply();
    }

    public static void setFlag(String key, boolean flag) {
        getAppPreference()
                .edit()
                .putBoolean(key, flag)
                .apply();
    }

    public static boolean getFlag(String key) {
        return getAppPreference()
                .getBoolean(key, false);
    }

    public static void setData(String key, String val) {
        getAppPreference()
                .edit()
                .putString(key, val)
                .apply();
    }

    public static String getData(String key) {
        return getAppPreference().getString(key, "");
    }

}
